package com.example.task1.ui.AllService.YouthStation;

import android.os.Bundle;
import android.text.Html;
import android.view.MenuItem;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.PersonDetailsBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import retrofit2.Call;

public class PersonDetailsActivity extends AppCompatActivity {

    private int id;
    private TextView tvTitle;
    private TextView tvName;
    private TextView tvContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_person_details);
        ActionBar supportActionBar = getSupportActionBar();
        supportActionBar.setTitle("详情");
        supportActionBar.setDisplayHomeAsUpEnabled(true);
        id = getIntent().getIntExtra("id", 0);
        initData();
        initView();
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    private void initData() {
        Call<ApiResp> apiRespCall = Api.api().get(MyApplication.TOKEN, "/prod-api/api/youth-inn/talent-policy/" + id);
        Api.send(apiRespCall, PersonDetailsBean.class, new CallBack<PersonDetailsBean>() {
            @Override
            public void success(PersonDetailsBean data) {
                PersonDetailsBean.DataDTO rows = data.getData();
                tvTitle.setText(rows.getTitle());
                tvName.setText("---"+rows.getAuthor());
                tvContent.setText(Html.fromHtml(rows.getContent()));
            }

            @Override
            public void error(String msg) {

            }
        });
    }

    private void initView() {
        tvTitle = (TextView) findViewById(R.id.tv_title);
        tvName = (TextView) findViewById(R.id.tv_name);
        tvContent = (TextView) findViewById(R.id.tv_content);
    }
}